const filmsManageModel = require("../model/filmsManageModel");
//新增电影
module.exports.insert = async function (film) {
    return await filmsManageModel.create(film);
}
//删除电影
module.exports.delete = async function (id) {
    return await filmsManageModel.deleteOne({ _id: id });
}
//修改电影
module.exports.update = async function (film) {
    return await filmsManageModel.updateOne({ _id: film._id }, film);
}
//查询所有电影
module.exports.find = async function (page, searchParams) {
    let { current, pageSize } = page;
    // 根据查询条件获取总数
    let total = await filmsManageModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    let data = await filmsManageModel.find(searchParams)
        .limit(pageSize)//限制查询数量
        .skip((current - 1) * pageSize);//从下标0-n开始查询
    return { current, pageSize, total, rows: data }//rows:data每行显示数据
}
//通过ID查询
module.exports.findById = async function(id){
    return await filmsManageModel.findById(id);
}